import openai
openai.api_key = "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"

def analyze_text(text):
    response = openai.Completion.create(
        engine="davinci",
        prompt=(f"情感分析：{text}，涉及的地点是哪里？\n"
                f"情感分为高兴、悲伤、惊讶、愤怒、喜欢、不喜欢、紧张、放松、好奇、自豪\n"
                f"用五个字以内回答"),
        temperature=0.5,
        max_tokens=50,
        n=1,
        stop=None,
        timeout=15,
    )

    if response.choices[0].text.strip() == '':
        return '无法分析'

    return response.choices[0].text.strip()

text = input("请输入要分析的文本：")
result = analyze_text(text)
print(result)
